package net.m510.autosurfer.mhbk;

import net.m510.autosurfer.common.exception.CannotLoginException;
import net.m510.autosurfer.common.exception.UnknownClientException;
import net.m510.autosurfer.core.DocumentChecker;
import net.m510.autosurfer.core.utils.AnalyzeUtils;

import org.jsoup.nodes.Document;
import org.jsoup.nodes.FormElement;


public class MhbkLoginUserNumChecker implements DocumentChecker {
	private String ERR_UNCORRECT_INPUT = "EMFk93";
	@Override
	public void check(Document doc) throws CannotLoginException,UnknownClientException {
		// 入力内容が正しくありません
		if ( doc.body().html().contains(ERR_UNCORRECT_INPUT)) {
			CannotLoginException cle = new CannotLoginException(
					doc.body().getElementsContainingOwnText(ERR_UNCORRECT_INPUT).first().text()
					);
			cle.setDocument(doc);
			throw cle;
		}
		// 端末未登録チェック
		if ( doc.body().html().contains("合言葉確認")) {
			UnknownClientException uce = new UnknownClientException();
			uce.setDocument(doc);
			throw uce;
		}
		// その他エラー
		final String FORM_ID="LOGBNK_00005B";
		FormElement form = AnalyzeUtils.getFormElementByName(doc, FORM_ID);
		if ( form == null ) throw new CannotLoginException("no form :"+FORM_ID,doc);
		
		return;
	}
}
